# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
$(document).on 'page:change', ->
  $(document).on 'click', '#submit_user_group_popover', ->
    data = {}
    $('#user_group_popover').find('input').each ->
      data[$(this).attr('name')] = $(this).val()

    $.post '/user_groups.json', data, (result)->
      $('#user_group_id_').append("<option value=\"#{result.id}\">#{result.name}</option>")
      $('#user_group_id_').val(result.id)

    $('#add_user_group').popover('toggle');